using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;

using Framework;

namespace SchemaMonitor
{
    [Serializable()]
    public partial class CPublishImage : CBaseDynamic, IComparable<CPublishImage>
    {
        #region Constructors
        //Public (Copy Constructor)
        public CPublishImage(CPublishImage original, CDataSrc target)
        {
            //Database Connection
            m_dataSrc = target;

            //Copy fields
            _pubImgPublishId = original.PubImgPublishId;
            _pubImgPictureId = original.PubImgPictureId;
            _pubImgPictureFileSize = original.PubImgPictureFileSize;
            _pubImgPictureComments = original.PubImgPictureComments;
            _pubImgPictureHasCaption = original.PubImgPictureHasCaption;
            _pubImgTempPostId = original.PubImgTempPostId;
            _pubImgTempPostMs = original.PubImgTempPostMs;
            _pubImgFinalPictureId = original.PubImgFinalPictureId;
            _pubImgFinalPictureComments = original.PubImgFinalPictureComments;
            _pubImgFinalPictureCommentsMs = original.PubImgFinalPictureCommentsMs;
        }

        //Protected (Datareader/Dataset)
        protected CPublishImage(CDataSrc dataSrc, IDataReader dr) : base(dataSrc, dr) {}
        protected CPublishImage(CDataSrc dataSrc, DataRow     dr) : base(dataSrc, dr) {}
        #endregion

        #region Default Values
        protected override void InitValues_Auto()
        {
            //Null-Equivalent values (except String.Empty, as nulls tend to be inconvenient for string types)
            _pubImgId = int.MinValue;
            _pubImgPublishId = int.MinValue;
            _pubImgPictureId = int.MinValue;
            _pubImgPictureFileSize = long.MinValue;
            _pubImgPictureComments = int.MinValue;
            _pubImgPictureHasCaption = false;
            _pubImgTempPostId = int.MinValue;
            _pubImgTempPostMs = long.MinValue;
            _pubImgFinalPictureId = long.MinValue;
            _pubImgFinalPictureComments = int.MinValue;
            _pubImgFinalPictureCommentsMs = long.MinValue;
        }
        #endregion

        #region Members
        protected int _pubImgId;
        protected int _pubImgPublishId;
        protected int _pubImgPictureId;
        protected long _pubImgPictureFileSize;
        protected int _pubImgPictureComments;
        protected bool _pubImgPictureHasCaption;
        protected int _pubImgTempPostId;
        protected long _pubImgTempPostMs;
        protected long _pubImgFinalPictureId;
        protected int _pubImgFinalPictureComments;
        protected long _pubImgFinalPictureCommentsMs;
        #endregion

        #region Properties - Column Values
        //Primary Key Column (ReadOnly)
        public int PubImgId    {   get { return _pubImgId;   } }

        //Table Columns (Read/Write)
        public int PubImgPublishId    {   get { return _pubImgPublishId; } set { _pubImgPublishId = value; }    }
        public int PubImgPictureId    {   get { return _pubImgPictureId; } set { _pubImgPictureId = value; }    }
        public long PubImgPictureFileSize    {   get { return _pubImgPictureFileSize; } set { _pubImgPictureFileSize = value; }    }
        public int PubImgPictureComments    {   get { return _pubImgPictureComments; } set { _pubImgPictureComments = value; }    }
        public bool PubImgPictureHasCaption    {   get { return _pubImgPictureHasCaption; } set { _pubImgPictureHasCaption = value; }    }
        public int PubImgTempPostId    {   get { return _pubImgTempPostId; } set { _pubImgTempPostId = value; }    }
        public long PubImgTempPostMs    {   get { return _pubImgTempPostMs; } set { _pubImgTempPostMs = value; }    }
        public long PubImgFinalPictureId    {   get { return _pubImgFinalPictureId; } set { _pubImgFinalPictureId = value; }    }
        public int PubImgFinalPictureComments    {   get { return _pubImgFinalPictureComments; } set { _pubImgFinalPictureComments = value; }    }
        public long PubImgFinalPictureCommentsMs    {   get { return _pubImgFinalPictureCommentsMs; } set { _pubImgFinalPictureCommentsMs = value; }    }

        //View Columns (ReadOnly)

        #endregion

        #region MustOverride Methods
        //Schema Information
        public const string TABLE_NAME      = "PublishImages";
        public const string VIEW_NAME       = "";         //Used to override this.ViewName { get }
        public const string ORDER_BY_COLS   = "PubImgId";   //See the CompareTo method below (Sql-based sorting should match In-Memory sorting)
        public const string SORTING_COLUMN  = "";
        public override string TableName {    get { return TABLE_NAME; } }
        protected override string OrderByColumns {    get { return ORDER_BY_COLS; } }

        //CompareTo Interface (Default Sort Order)
        public int CompareTo(CPublishImage other) {   return this.PubImgId.CompareTo(other.PubImgId) ;  }

        //Primary Key Information
        public const string PRIMARY_KEY_NAME = "PubImgId";
        protected override bool InsertPrimaryKey {  get { return false;    }   }
        protected override string PrimaryKeyName {  get { return PRIMARY_KEY_NAME;    }    }
        protected override object PrimaryKeyValue 
        {
              get { return _pubImgId; }
              set { _pubImgId = (int)value; }
        }

        //Factory Methods - Object
        protected override CBase MakeFrom(DataRow row)      {   return new CPublishImage(this.DataSrc, row);  }
        protected override CBase MakeFrom(IDataReader dr)   {   return new CPublishImage(this.DataSrc, dr);   }

        //Factory Methods - List
        protected override IList MakeList()                 {   return new CPublishImageList();               }
        protected override IList MakeList(int capacity)     {   return new CPublishImageList(capacity);       }

        //Convert from ADO to .Net
        protected override void ReadColumns(IDataReader dr)
        {
            _pubImgId = CAdoData.GetInt(dr, "PubImgId");
            _pubImgPublishId = CAdoData.GetInt(dr, "PubImgPublishId");
            _pubImgPictureId = CAdoData.GetInt(dr, "PubImgPictureId");
            _pubImgPictureFileSize = CAdoData.GetLong(dr, "PubImgPictureFileSize");
            _pubImgPictureComments = CAdoData.GetInt(dr, "PubImgPictureComments");
            _pubImgPictureHasCaption = CAdoData.GetBool(dr, "PubImgPictureHasCaption");
            _pubImgTempPostId = CAdoData.GetInt(dr, "PubImgTempPostId");
            _pubImgTempPostMs = CAdoData.GetLong(dr, "PubImgTempPostMs");
            _pubImgFinalPictureId = CAdoData.GetLong(dr, "PubImgFinalPictureId");
            _pubImgFinalPictureComments = CAdoData.GetInt(dr, "PubImgFinalPictureComments");
            _pubImgFinalPictureCommentsMs = CAdoData.GetLong(dr, "PubImgFinalPictureCommentsMs");
        }
        protected override void ReadColumns(DataRow dr)
        {
            _pubImgId = CAdoData.GetInt(dr, "PubImgId");
            _pubImgPublishId = CAdoData.GetInt(dr, "PubImgPublishId");
            _pubImgPictureId = CAdoData.GetInt(dr, "PubImgPictureId");
            _pubImgPictureFileSize = CAdoData.GetLong(dr, "PubImgPictureFileSize");
            _pubImgPictureComments = CAdoData.GetInt(dr, "PubImgPictureComments");
            _pubImgPictureHasCaption = CAdoData.GetBool(dr, "PubImgPictureHasCaption");
            _pubImgTempPostId = CAdoData.GetInt(dr, "PubImgTempPostId");
            _pubImgTempPostMs = CAdoData.GetLong(dr, "PubImgTempPostMs");
            _pubImgFinalPictureId = CAdoData.GetLong(dr, "PubImgFinalPictureId");
            _pubImgFinalPictureComments = CAdoData.GetInt(dr, "PubImgFinalPictureComments");
            _pubImgFinalPictureCommentsMs = CAdoData.GetLong(dr, "PubImgFinalPictureCommentsMs");
        }

        //Parameters for Insert/Update    
        protected override CNameValueList ColumnNameValues()
        {
            CNameValueList data = new CNameValueList();
            data.Add("PubImgId", CAdoData.NullVal(_pubImgId));
            data.Add("PubImgPublishId", CAdoData.NullVal(_pubImgPublishId));
            data.Add("PubImgPictureId", CAdoData.NullVal(_pubImgPictureId));
            data.Add("PubImgPictureFileSize", CAdoData.NullVal(_pubImgPictureFileSize));
            data.Add("PubImgPictureComments", CAdoData.NullVal(_pubImgPictureComments));
            data.Add("PubImgPictureHasCaption", CAdoData.NullVal(_pubImgPictureHasCaption));
            data.Add("PubImgTempPostId", CAdoData.NullVal(_pubImgTempPostId));
            data.Add("PubImgTempPostMs", CAdoData.NullVal(_pubImgTempPostMs));
            data.Add("PubImgFinalPictureId", CAdoData.NullVal(_pubImgFinalPictureId));
            data.Add("PubImgFinalPictureComments", CAdoData.NullVal(_pubImgFinalPictureComments));
            data.Add("PubImgFinalPictureCommentsMs", CAdoData.NullVal(_pubImgFinalPictureCommentsMs));
            return data;
        }
        #endregion

        #region Queries - SelectAll/SelectWhere (inherited methods, cast only)
        //Select Queries - Non-Paged
        public new CPublishImageList SelectAll()                                                          {    return (CPublishImageList)base.SelectAll();                              }
        public new CPublishImageList SelectAll(string orderBy)                                            {    return (CPublishImageList)base.SelectAll(orderBy);                       }
        public new CPublishImageList SelectWhere(string colName, ESign sign, object colValue)             {    return (CPublishImageList)base.SelectWhere(colName, sign, colValue);     }
        public new CPublishImageList SelectWhere(CCriteria where)                                         {    return (CPublishImageList)base.SelectWhere(where);                       }
        public new CPublishImageList SelectWhere(CCriteriaList where)                                     {    return (CPublishImageList)base.SelectWhere(where);                       }
        public new CPublishImageList SelectWhere(CCriteriaList where, string tableOrJoin)                 {    return (CPublishImageList)base.SelectWhere(where, tableOrJoin);          }
        public new CPublishImageList SelectWhere(CCriteriaList where, string tableOrJoin, string orderBy) {    return (CPublishImageList)base.SelectWhere(where, tableOrJoin, orderBy); }
        [Obsolete("Arbitrary where-clause is not necessary portable or safe from sql injection attacks. Consider using the parameterised query interfaces")]
        public new CPublishImageList SelectWhere(string unsafeWhereClause)                                {    return (CPublishImageList)base.SelectWhere(unsafeWhereClause);           }
        public     CPublishImageList SelectById(int pubImgId)                              {    return (CPublishImageList)base.SelectById(pubImgId);       }
        public     CPublishImageList SelectByIds(List<int> ids)                        {    return (CPublishImageList)base.SelectByIds(ids);                         }

        //Select Queries - Paged
        public new CPublishImageList SelectAll(  CPagingInfo pi)                                              {    return (CPublishImageList)base.SelectAll(  pi);                              }
        public new CPublishImageList SelectWhere(CPagingInfo pi, string name, ESign sign, object value)       {    return (CPublishImageList)base.SelectWhere(pi, name, sign, value);           }
        public new CPublishImageList SelectWhere(CPagingInfo pi, CCriteria criteria)                          {    return (CPublishImageList)base.SelectWhere(pi, criteria);                    }
        public new CPublishImageList SelectWhere(CPagingInfo pi, CCriteriaList criteria)                      {    return (CPublishImageList)base.SelectWhere(pi, criteria);                    }
        public new CPublishImageList SelectWhere(CPagingInfo pi, CCriteriaList criteria, string viewOrJoin)   {    return (CPublishImageList)base.SelectWhere(pi, criteria, viewOrJoin);        }
        public     CPublishImageList SelectByIds(CPagingInfo pi, List<int> ids)            {    return (CPublishImageList)base.SelectByIds(pi, ids);                         }

        //Select Queries - Transactional
        public new CPublishImageList SelectAll(                                                                                           IDbTransaction tx)  {    return (CPublishImageList)base.SelectAll(tx);                                                     }
        public new CPublishImageList SelectAll(string orderBy,                                                                            IDbTransaction tx)  {    return (CPublishImageList)base.SelectAll(orderBy,                                         tx);    }
        public new CPublishImageList SelectWhere(string columnName,               object columnValue,                                     IDbTransaction tx)  {    return (CPublishImageList)base.SelectWhere(columnName,              columnValue,          tx);    }
        public new CPublishImageList SelectWhere(string columnName,   ESign sign, object columnValue,                                     IDbTransaction tx)  {    return (CPublishImageList)base.SelectWhere(columnName,    sign,     columnValue,          tx);    }
        public new CPublishImageList SelectWhere(                             CCriteria     criteria,                                     IDbTransaction tx)  {    return (CPublishImageList)base.SelectWhere(               criteria,                       tx);    }
        public new CPublishImageList SelectWhere(                             CCriteriaList criteria,                                     IDbTransaction tx)  {    return (CPublishImageList)base.SelectWhere(               criteria,                       tx);    }
        public new CPublishImageList SelectWhere(                             CCriteriaList criteria, string tableOrJoin,                 IDbTransaction tx)  {    return (CPublishImageList)base.SelectWhere(               criteria, tableOrJoin,          tx);    }
        public new CPublishImageList SelectWhere(                             CCriteriaList criteria, string tableOrJoin, string orderBy, IDbTransaction tx)  {    return (CPublishImageList)base.SelectWhere(               criteria, tableOrJoin,          tx);    }
        public     CPublishImageList SelectById(int pubImgId,                                                              IDbTransaction tx)  {    return (CPublishImageList)base.SelectById(pubImgId,                         tx);    }
        public     CPublishImageList SelectByIds(List<int> ids,                                                        IDbTransaction tx)  {    return (CPublishImageList)base.SelectByIds(ids,                                           tx);    }

        //Select Queries - Stored Procs
        public new CPublishImageList MakeList(string storedProcName,                             IDbTransaction txOrNull)    {   return (CPublishImageList)base.MakeList(storedProcName,             txOrNull);  }
        public new CPublishImageList MakeList(string storedProcName, object[] parameters,        IDbTransaction txOrNull)    {   return (CPublishImageList)base.MakeList(storedProcName, parameters, txOrNull);  }
        public new CPublishImageList MakeList(string storedProcName, CNameValueList parameters,  IDbTransaction txOrNull)    {   return (CPublishImageList)base.MakeList(storedProcName, parameters, txOrNull);  }
        public new CPublishImageList MakeList(string storedProcName, List<object> parameters,    IDbTransaction txOrNull)    {   return (CPublishImageList)base.MakeList(storedProcName, parameters, txOrNull);  }
        public new CPublishImageList MakeList(string storedProcName, int param1,                 IDbTransaction txOrNull)    {   return (CPublishImageList)base.MakeList(storedProcName, param1,     txOrNull);  }
        public new CPublishImageList MakeList(string storedProcName, string param1,              IDbTransaction txOrNull)    {   return (CPublishImageList)base.MakeList(storedProcName, param1,     txOrNull);  }

        //Query Results
        protected new CPublishImageList MakeList(DataSet              ds) { return (CPublishImageList)base.MakeList(ds);        }
        protected new CPublishImageList MakeList(DataTable            dt) { return (CPublishImageList)base.MakeList(dt);        }
        protected new CPublishImageList MakeList(DataRowCollection  rows) { return (CPublishImageList)base.MakeList(rows);      }
        protected new CPublishImageList MakeList(IDataReader          dr) { return (CPublishImageList)base.MakeList(dr);        }
        protected new CPublishImageList MakeList(object           drOrDs) { return (CPublishImageList)base.MakeList(drOrDs);    }        
        protected new CPublishImageList MakeList(byte[]             gzip) { return (CPublishImageList)base.MakeList(gzip);      }
        #endregion

        #region Queries - SelectBy[FK] (user-nominated fk/bool columns)
        //Non-Paged
        public CPublishImageList SelectByPublishId(int pubImgPublishId)    {    return SelectWhere(new CCriteriaList("PubImgPublishId", pubImgPublishId));    }
        public CPublishImageList SelectByPictureId(int pubImgPictureId)    {    return SelectWhere(new CCriteriaList("PubImgPictureId", pubImgPictureId));    }
        public CPublishImageList SelectByPictureHasCaption(bool pubImgPictureHasCaption)    {    return SelectWhere(new CCriteriaList("PubImgPictureHasCaption", pubImgPictureHasCaption));    }
        public CPublishImageList SelectByTempPostId(int pubImgTempPostId)    {    return SelectWhere(new CCriteriaList("PubImgTempPostId", pubImgTempPostId));    }
        public CPublishImageList SelectByFinalPictureId(long pubImgFinalPictureId)    {    return SelectWhere(new CCriteriaList("PubImgFinalPictureId", pubImgFinalPictureId));    }

        //Paged
        public CPublishImageList SelectByPublishId(CPagingInfo pi, int pubImgPublishId)    {    return SelectWhere(pi, new CCriteriaList("PubImgPublishId", pubImgPublishId));    }
        public CPublishImageList SelectByPictureId(CPagingInfo pi, int pubImgPictureId)    {    return SelectWhere(pi, new CCriteriaList("PubImgPictureId", pubImgPictureId));    }
        public CPublishImageList SelectByPictureHasCaption(CPagingInfo pi, bool pubImgPictureHasCaption)    {    return SelectWhere(pi, new CCriteriaList("PubImgPictureHasCaption", pubImgPictureHasCaption));    }
        public CPublishImageList SelectByTempPostId(CPagingInfo pi, int pubImgTempPostId)    {    return SelectWhere(pi, new CCriteriaList("PubImgTempPostId", pubImgTempPostId));    }
        public CPublishImageList SelectByFinalPictureId(CPagingInfo pi, long pubImgFinalPictureId)    {    return SelectWhere(pi, new CCriteriaList("PubImgFinalPictureId", pubImgFinalPictureId));    }

        //Count
        public int SelectCountByPublishId(int pubImgPublishId)   {   return SelectCount(new CCriteriaList("PubImgPublishId", pubImgPublishId));     }
        public int SelectCountByPictureId(int pubImgPictureId)   {   return SelectCount(new CCriteriaList("PubImgPictureId", pubImgPictureId));     }
        public int SelectCountByPictureHasCaption(bool pubImgPictureHasCaption)   {   return SelectCount(new CCriteriaList("PubImgPictureHasCaption", pubImgPictureHasCaption));     }
        public int SelectCountByTempPostId(int pubImgTempPostId)   {   return SelectCount(new CCriteriaList("PubImgTempPostId", pubImgTempPostId));     }
        public int SelectCountByFinalPictureId(long pubImgFinalPictureId)   {   return SelectCount(new CCriteriaList("PubImgFinalPictureId", pubImgFinalPictureId));     }

        //Transactional
        public CPublishImageList SelectByPublishId(int pubImgPublishId, IDbTransaction tx)    {    return SelectWhere(new CCriteriaList("PubImgPublishId", pubImgPublishId), tx);    }
        public CPublishImageList SelectByPictureId(int pubImgPictureId, IDbTransaction tx)    {    return SelectWhere(new CCriteriaList("PubImgPictureId", pubImgPictureId), tx);    }
        public CPublishImageList SelectByPictureHasCaption(bool pubImgPictureHasCaption, IDbTransaction tx)    {    return SelectWhere(new CCriteriaList("PubImgPictureHasCaption", pubImgPictureHasCaption), tx);    }
        public CPublishImageList SelectByTempPostId(int pubImgTempPostId, IDbTransaction tx)    {    return SelectWhere(new CCriteriaList("PubImgTempPostId", pubImgTempPostId), tx);    }
        public CPublishImageList SelectByFinalPictureId(long pubImgFinalPictureId, IDbTransaction tx)    {    return SelectWhere(new CCriteriaList("PubImgFinalPictureId", pubImgFinalPictureId), tx);    }
        #endregion

        #region ToXml
        protected override void ToXml_Autogenerated(System.Xml.XmlWriter w)
        {
            Store(w, "PubImgId", this.PubImgId);
            Store(w, "PubImgPublishId", this.PubImgPublishId);
            Store(w, "PubImgPictureId", this.PubImgPictureId);
            Store(w, "PubImgPictureFileSize", this.PubImgPictureFileSize);
            Store(w, "PubImgPictureComments", this.PubImgPictureComments);
            Store(w, "PubImgPictureHasCaption", this.PubImgPictureHasCaption);
            Store(w, "PubImgTempPostId", this.PubImgTempPostId);
            Store(w, "PubImgTempPostMs", this.PubImgTempPostMs);
            Store(w, "PubImgFinalPictureId", this.PubImgFinalPictureId);
            Store(w, "PubImgFinalPictureComments", this.PubImgFinalPictureComments);
            Store(w, "PubImgFinalPictureCommentsMs", this.PubImgFinalPictureCommentsMs);
        }
        #endregion

    }
}
